<?php

namespace app\backend\controller;

use app\common\Auth;
use think\Controller;
use think\Request;

class Login extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return $this->fetch();
    }

    /**
     * @param Auth $auth
     * @param Request $request
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function login(Auth $auth, Request $request)
    {
        $username = $request->post("username");
        $password = $request->post("password");
        if($username == "" || $password == "") {
            $this->error("请填写完整的用户信息");
        }
        if(!$auth->login($username,$password)){
            $this->error("用户名或者密码错误");
        }
        $this->redirect(url("/admin"));
    }

}
